package org.openea.eap.module.obpm.controller.admin.sync;


import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.openea.eap.framework.common.pojo.CommonResult;
import org.openea.eap.module.obpm.service.obpm.sync.ObpmOrgSyncService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@Tag(name = "OpenBPM sync")
@RestController
@Slf4j
public class ObpmSyncController {

    @Resource
    private ObpmOrgSyncService obpmOrgSyncService;

    // 重新同步所有用户
    @GetMapping("/obpm/resyncAllUsers")
    public CommonResult<Integer> resyncAllUsers(){
        return CommonResult.success(obpmOrgSyncService.syncUser(null));
    }
    // 同步指定更新日期之后数据，默认一周内
    @GetMapping("/obpm/syncUsers")
    public CommonResult<Integer> syncUsers(@RequestParam("lastSyncDate") Date lastSyncDate){
        if(lastSyncDate==null){
            lastSyncDate = DateUtil.lastWeek();
        }
        return CommonResult.success(obpmOrgSyncService.syncUser(lastSyncDate));
    }

    @GetMapping("/obpm/syncEmail")
    public CommonResult<Integer> syncEmail(){
        return CommonResult.success(obpmOrgSyncService.syncEmail());
    }
}
